import 'package:demo202112/utils/common_appbar.dart';
import 'package:flutter/material.dart';
/**
 * @Author wywinstonwy
 * @Date 2021/12/30 11:02 下午
 * @Description:
 */

class WyDraggable extends StatefulWidget {
  const WyDraggable({Key? key}) : super(key: key);

  @override
  _WyDraggableState createState() => _WyDraggableState();
}

class _WyDraggableState extends State<WyDraggable> {
  var _dragData;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar('Draggable'),
      body:_buildView2() ,
    );
  }
  _buildView1(){
    return Draggable(
      // axis: Axis.vertical,
        child: Container(
          height: 100,
          width: 100,
          alignment: Alignment.center,
          decoration: BoxDecoration(
            color: Colors.red,
            borderRadius: BorderRadius.circular(10)
          ),
          child: Text('璋',style: TextStyle(color: Colors.white,fontSize: 20),),
        ),
        feedback: Container(
          height: 100,
          width: 100,
          alignment: Alignment.center,
          decoration: BoxDecoration(
              color: Colors.blue,
              borderRadius: BorderRadius.circular(10)
          ),
          child: Text('三',style: TextStyle(color: Colors.white,fontSize: 20),),
        ),
      childWhenDragging: Container(
        height: 100,
        width: 100,
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: Colors.grey,
          borderRadius: BorderRadius.circular(10),
        ),
        child: Text('王',
          style: TextStyle(
              color: Colors.white,
              fontSize: 18),
        ),
      ),
      onDragStarted: (){
        print('onDragStarted');
      },
      onDragEnd: (DraggableDetails details){
        print('onDragEnd:$details');
      },
      onDraggableCanceled: (Velocity velocity,Offset offset){
        print('onDraggableCancel velocity:$velocity,offset:$offset');
      },
      onDragCompleted: (){
        print('onDragCompleted');
      },
      onDragUpdate: (DragUpdateDetails details){
          print('onDragUpdate');
      },
    );
  }
  _buildView2() {
    return DragTarget(
      builder: (BuildContext context, List<Object?> candidateData,
          List<dynamic> rejectedData) {
        return Container(
          alignment: Alignment.center,
          height: 250,
          width: 250,
          color: Colors.black26,
          child: Text('data'),
        );
      },
      onAccept: (String data) {
        print(data);
      },
      onLeave:( data){
        //数据来了 又离开了
        print('onLeave : $data');
      },

    );
  }
}
